import axios from './axios';

const loginUrl = 'login'; // 用户登录
const postUserInfoUrl = 'user'; // 个人基础信息 user

export default {
  // 个人基础信息
  userInfo(obj) {
    const postObj = {
      userName: obj.userName,
      birday: obj.birday,
      phone: obj.phone,
      addr: obj.addr,
      email: obj.email,
      experience: obj.experience,
      imageUrl: obj.imageUrl,
    };
    return axios.post(`${postUserInfoUrl}`, postObj);
  },
  // 编辑管理员
  putUser(obj) {
    const postObj = {
      id: obj.id,
      userName: obj.userName,
      birday: obj.birday,
      phone: obj.phone,
      addr: obj.addr,
      email: obj.email,
      experience: obj.experience,
      imageUrl: obj.imageUrl,
    };
    return axios.put(`${postUserInfoUrl}`, postObj);
  },
  // 获取该用户个人基础信息
  getUserInfo(id) {
    console.log('id=', id);
    return axios({
      url: `${postUserInfoUrl}/detail`,
      method: 'get',
      params: { id },
    });
  },
  // 个人基础信息列表
  userList() {
    return axios.get(`${postUserInfoUrl}/list`);
  },
  // 删除个人基础信息
  delUser(id) {
    return axios.delete(`${postUserInfoUrl}?id=${id}`);
  },
  // 用户登录
  userLogin(obj) {
    const postObj = {
      username: obj.userName,
      password: obj.pass,
    };
    return axios.post(`${loginUrl}`, postObj);
  },
};
